﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;

namespace Icinetic.FeedCategorySample.CrossCutting
{
    public static class IOExtensions
    {
        public static async Task<bool> FileExistsAsync(this StorageFolder srcFolder, string fileName)
        {
            bool exists = true;

            try
            {
                await srcFolder.GetFileAsync(fileName);
            }
            catch (FileNotFoundException)
            {
                exists = false;
            }

            return exists;
        }

        public static async Task<bool> FolderExistsAsync(this StorageFolder srcFolder, string folderName)
        {
            bool exists = true;

            try
            {
                await srcFolder.GetFolderAsync(folderName);
            }
            catch (FileNotFoundException)
            {
                exists = false;
            }

            return exists;
        }
    }
}
